#include <iostream>
#include "protocol.hpp"

using namespace protocol_ns;

class Calcaulate
{
public:
    Calcaulate() {}
    Response excute(Request &req)
    {
        //Log(DEBUG,"excuting");
        int result = 0, code = 0;
        switch (req.Getoper())
        {
        case '+':
            result = req.Getx() + req.Gety();
            break;
        case '-':
            result = req.Getx() - req.Gety();
            break;
        case '*':
            result = req.Getx() * req.Gety();
            break;
        case '/':
            if (req.Gety() == 0)
            {
                code = 1; // 除零错误
            }
            else
            {
                result = req.Getx() / req.Gety();
            }
            break;
        case '%':
            if (req.Gety() == 0)
            {
                code = 2; // 取余0错误
            }
            else
            {
                result = req.Getx() / req.Gety();
            }
            break;
        default:
            code = 3; // 运算符错误
            break;
        }
        Response res(result,code);
        return res;
    }
    ~Calcaulate() {}

private:
};